﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Area.SystemManager;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.PoModel.ContractModel;
using SystemCenterSoa.Service.ContractManger;

namespace SystemCenterSoa.ApiProject.Area.ContractManger
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ContractControllers : SystemManagerBaseController
    {
        private ContractService _customerService;

        public ContractControllers(ContractService customerService)
        {
            _customerService = customerService;
        }

        [HttpPost]
        public ResultModel<bool> AgreementAdd(AgreementPo info)
        {
            try
            {
                var data = _customerService.AgreementAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> ContractAdd(ContractPo info)
        {
            try
            {
                var data = _customerService.ContractAdd(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<Contype>> GetContype()
        {
            try
            {
                var data = _customerService.GetContype();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<Contype>>(ex);
            }
        }
        [AllowAnonymous]
        [HttpGet]
        public ResultModel<List<StructurePo>> GetStruct()
        {
            try
            {
                var data = _customerService.GetStruct();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<StructurePo>>(ex);
            }
        }
        [AllowAnonymous]
        [HttpGet]
        public ResultModel<List<ArchitecturePo>> GetArchite()
        {
            try
            {
                var data = _customerService.GetArchite();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<ArchitecturePo>>(ex);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public ResultModel<PagerResult<ContractPo>> GetContract(SearchModel searchModel)
        {

            try
            {
                var list = _customerService.GetContract(searchModel);
                return MyOk(list);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<ContractPo>>(ex);
            }
        }

        [AllowAnonymous]
        [HttpGet]
        public ResultModel<List<AgreementPo>> GetAgreelast()
        {
            try
            {
                var data = _customerService.GetAgreelast();
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<List<AgreementPo>>(ex);
            }
        }

        [HttpGet]
        public ResultModel<AgreementPo> LastCha(int id)
        {
            try
            {
                var data = _customerService.LastCha(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<AgreementPo>(ex);
            }
        }

        [HttpGet]
        public ResultModel<ContractPo> FanAgree(int id)
        {
            try
            {
                var data = _customerService.FanAgree(id);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<ContractPo>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> UpdateContr(ContractPo info)
        {
            try
            {
                var data = _customerService.UpdateContr(info);
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }
    }
}
